package com.schoolpro.controller;


import com.schoolpro.pojo.DTO.PropertyAddDTO;
import com.schoolpro.pojo.DTO.PropertyDTO;
import com.schoolpro.pojo.DTO.PropertyUpdateDTO;
import com.schoolpro.pojo.Request;
import com.schoolpro.pojo.Result;
import com.schoolpro.service.PropertyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author : Hinton
* @时间 : 2月 04 23:48
*/


@RestController
@RequestMapping("/property")
@Slf4j
@Tag(name = "属性管理")
public class PropertyController {
    @Autowired
    private PropertyService propertyService;

    /**
     * 添加属性
     * @param categoryPropertyAddRequest
     * @return
     */
    @PostMapping("/add")
    @Operation(summary = "添加属性")
    public Result<Object> addCategoryProperty(@RequestBody Request<PropertyAddDTO> propertyAddDTO) {
        log.info("添加属性{}", propertyAddDTO.getParam());
        propertyService.addPropertyBatch(propertyAddDTO.getParam());
        return Result.success();
    }

    @DeleteMapping
    public Result<Object> deleteProperty(@RequestBody List<Integer> ids) {
        log.info("删除属性{}", ids);
        propertyService.deleteProperty(ids);
        return Result.success();
    }

    @PutMapping
    @Operation(summary = "修改属性")
    public Result<Object> updateProperty(@RequestBody Request<PropertyUpdateDTO> propertyUpdateDTO) {
        log.info("修改属性{}", propertyUpdateDTO.getParam());
        propertyService.updateProperty(propertyUpdateDTO.getParam());
        return Result.success();
    }
}
